//
//  UIButton+Extension.swift
//  个人微博
//
//  Created by 一介布衣 on 16/2/17.
//  Copyright © 2016年 HUAMANLOU. All rights reserved.
//

import UIKit

// 给UIButton做扩展
extension UIButton {

    // 类工厂方法
    // 1.背景图片＋图片
    class func factoryBackgroundImgBtn(backImageName:String, imageName:String)->(UIButton) {
        let btn = UIButton()
        // 设置图片
        btn.setImage(UIImage(named: imageName), forState: .Normal)
        btn.setBackgroundImage(UIImage(named: backImageName), forState: .Normal)
        
        // 设置高亮图片
        btn.setImage(UIImage(named: imageName+"_highlighted"), forState: .Highlighted)
        btn.setBackgroundImage(UIImage(named: backImageName+"_highlighted"), forState: .Highlighted)
        
        return btn
    }
    
    // 2.背景图片＋文案
    class func factoryBtn(backImageName:String, text:String, textColor:UIColor)->(UIButton) {
        let btn = UIButton()
        // 设置文字
        btn.setTitle(text, forState: .Normal)
        btn.setBackgroundImage(UIImage(named: backImageName), forState: .Normal)
        btn.setTitleColor(textColor, forState: .Normal)
        
        return btn
    }

    
    // 扩展一个便利的构造方法
    // 1.背景图片＋图片
    convenience init(backImageName:String, imageName:String) {
        self.init()
        setImage(UIImage(named: imageName), forState: .Normal)
        setBackgroundImage(UIImage(named: backImageName), forState: .Normal)
        
        // 设置高亮图片
        setImage(UIImage(named: imageName), forState: .Highlighted)
        setBackgroundImage(UIImage(named: backImageName), forState: .Highlighted)
    }
    
    
    // 2.背景图片＋文案
    convenience init(backImageName:String, text:String, textColor:UIColor) {
        self.init()
        setBackgroundImage(UIImage(named: backImageName), forState: .Normal)
        setTitle(text, forState: .Normal)
        setTitleColor(textColor, forState: .Normal)
    }
   
}





